export class NetworkUtils {
    /**
     * 获取公网IP地址
     * @param timeout 超时时间（毫秒），默认3000
     */
    static async getPublicIP(timeout: number = 3000): Promise<any> {
        return  await new Promise<any>((resolve, reject) => {
            const xhr = new XMLHttpRequest();
            xhr.open('GET', 'https://game.gztywlkj.cn/IP', true);
            xhr.responseType = 'json';
            xhr.onload = (rej) => {
                if (xhr.status === 200) {
                    const data = xhr.response;
                    console.log()
                    resolve(data);
                }else{
                    console.log('xhr.status', xhr.status, xhr.responseText,rej);
                }
            }
            xhr.onerror = () => {
                console.log('xhr.onerror', xhr);
            }
            xhr.ontimeout = () => {
                console.log('xhr.ontimeout', xhr);
            }
            xhr.timeout = timeout;
            xhr.send();
        })
    }
}
